<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon" class="icon-title"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">
                                    <i :class="subItem.icon"></i>
                                    {{ subItem.title }}
                                    </template>
                                <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                            <i :class="subItem.icon"></i>
                            {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon" class="icon-title"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
export default {
    data() {
        return {
            items: [
                {icon: 'iconfont icon-home',index: '/welcome',title: '系统首页'},
                {icon: 'iconfont icon-icon-test50',index: '/error',title: '错误处理',subs: [
                    {icon: 'iconfont icon-icon-test63',index: '/404',title: '404页面'},
                    {icon: 'iconfont icon-icon-test62',index: '/403',title: '403页面'}
                ]},
                {icon: 'iconfont icon-layergroup-fill',index:"/base",title:'基础信息维护',subs:[
                    {icon: 'iconfont icon-copy-fill',index:'/constantCategory',title:'常数类别管理'},
                    {icon: 'iconfont icon-box',index:'/office',title:'科室管理'},
                    {icon: 'iconfont icon-user-group-fill',index:'/user',title:'用户管理'},
                    {icon: 'iconfont icon-user-group-fill',index:'/drugs',title:'非药品收费项目管理'}
                ]}
            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        },
        collapse(){
            return this.$store.state.collapse
        }
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
.icon-title{
    padding-right: 8px;
}
</style>
